package com.lex.controller;

import com.lex.common.annoatation.SysLog;
import com.lex.common.api.CommonResult;
import com.lex.common.enums.BusinessType;
import com.lex.entity.dept.AddDeptDto;
import com.lex.entity.dept.UpdateDeptDto;
import com.lex.entity.params.DeptQueryParams;
import com.lex.service.DeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
@Tag(name = "DeptController", description = "部门接口")
public class DeptController {
    @Resource
    private DeptService deptService;

    @Operation(summary = "获取所有部门")
    @RequestMapping(value = "/getAllDept",method = RequestMethod.GET)
    public CommonResult getAllDept(DeptQueryParams queryParamsDto){
        return deptService.getDeptList(queryParamsDto);
    }

    @Operation(summary = "添加部门")
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @SysLog(title = "添加部门", businessType = BusinessType.INSERT)
    public CommonResult addDept(@RequestBody AddDeptDto addDeptDto){
        return deptService.addDept(addDeptDto);
    }

    @Operation(summary = "修改部门")
    @RequestMapping(value = "/updateDept",method = RequestMethod.PUT)
    @SysLog(title = "修改部门", businessType = BusinessType.UPDATE)
    public CommonResult updateDept(@RequestBody UpdateDeptDto updateDeptDto){
        return deptService.updateDept(updateDeptDto);
    }

    @Operation(summary = "删除部门")
    @RequestMapping(value = "/deleteDept/{deptId}",method = RequestMethod.DELETE)
    @SysLog(title = "删除部门", businessType = BusinessType.DELETE)
    public CommonResult deleteDept(@PathVariable Long deptId){
        return  deptService.deleteDept(deptId);
    }
}
